﻿using ShareFrame.Business.Base_Manage;
using ShareFrame.Entity.Base_Manage;
using ShareFrame.Util;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;
using ShareFrame.IBusiness.Base_Manage;

namespace ShareFrame.Api.Controllers.Base_Manage
{
    /// <summary>
    /// 应用密钥
    /// </summary>
    /// <seealso cref="ShareFrame.Api.BaseApiController" />
    [Route("/Base_Manage/[controller]/[action]")]
    [OpenApiTag("应用密钥接口", Description = "用于应用密钥表的相关增删改查操作")]
    [ApiExplorerSettings(GroupName = "配置管理")]
    public class Base_AppSecretController : BaseApiController
    {
        #region DI

        public Base_AppSecretController(IBase_AppSecretBusiness appSecretBus)
        {
            _appSecretBus = appSecretBus;
        }

        IBase_AppSecretBusiness _appSecretBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 获取实体表中全部信息
        /// </summary>
        /// <param name="input">根据传入的参数查询并分页</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<Base_AppSecret>> GetDataList(PageInput<AppSecretsInputDTO> input)
        {
            return await _appSecretBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 获取指定实体信息
        /// </summary>
        /// <param name="input">传入的指定参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_AppSecret> GetTheData(IdInputDTO input)
        {
            return await _appSecretBus.GetTheDataAsync(input.id) ?? new Base_AppSecret();
        }

        #endregion

        #region 提交

        /// <summary>
        /// 保存提交非空验证调用对应方法
        /// </summary>
        /// <param name="data">保存的数据</param>
        [HttpPost]
        public async Task SaveData(Base_AppSecret data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await AddData(data);
            }
            else
            {
                await UpdateData(data);
            }
        }

        /// <summary>
        /// 基础添加方法
        /// </summary>
        /// <param name="data">待添加的实体信息</param>
        /// <returns></returns>
        [HttpPost]
        [ApiPermission("Base_AppSecret.Add")]
        public async Task AddData(Base_AppSecret data)
        {
            await _appSecretBus.AddDataAsync(data);
        }

        /// <summary>
        /// 基础更新方法
        /// </summary>
        /// <param name="data">待更新的实体信息</param>
        /// <returns></returns>
        [HttpPost]
        [ApiPermission("Base_AppSecret.Edit")]
        public async Task UpdateData(Base_AppSecret data)
        {
            await _appSecretBus.UpdateDataAsync(data);
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="ids">id数组,JSON数组</param>
        [HttpPost]
        [ApiPermission("Base_AppSecret.Delete")]
        public async Task DeleteData(List<string> ids)
        {
            await _appSecretBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}